#!/usr/bin/python3
import rospy
import airsim
# from lightcontrol.srv import lightIntensity, response
# from agxcar_ctrl.srv import _lightcontrol
from agxcar_ctrl.srv import lightcontrol
from agxcar_ctrl.srv import lightcontrolResponse
import time


def alarm_light():

    client= airsim.MultirotorClient("192.168.1.39")
    
    light_intensity_ = 2000.0
    client.client.call("setLightIntensity",light_intensity_,'')

    succeed_alarm_light = True

    return succeed_alarm_light

    # return lightcontrolResponse(True)

def attack_light():

    client= airsim.MultirotorClient("192.168.1.39")
    
    # 定义灯光强度值
    light_intensity_on = 2000.0  # 灯光打开时的强度
    light_intensity_off = 0.0   # 灯光关闭时的强度
    blink_count = 5             # 闪烁次数
    interval = 1  # 闪烁间隔（秒）

    # 设置灯光闪烁
    for _ in range(blink_count):
        client.setLightIntensity(light_intensity_on, '')
        time.sleep(interval)
        client.setLightIntensity(light_intensity_off, '')
        time.sleep(interval)

    # 最后一次闪烁后保持灯光开启或关闭，根据需要调整
    client.setLightIntensity(light_intensity_off, '')

    succeed_alarm_light = True
    return succeed_alarm_light

       


if __name__ == "__main__":
    import sys
    if len(sys.argv) > 1 and sys.argv[1] == "perform_alarm_light":
        succeed_alarm_light = False
        alarm_light()

    if len(sys.argv) > 1 and sys.argv[1] == "perform_attack_light":
        succeed_attack_light = False
        attack_light()
